package com.ming.mallchat.common.chat.service.adapter;

import com.ming.mallchat.common.chat.enums.HotFlagEnum;
import com.ming.mallchat.common.chat.enums.RoomTypeEnum;
import com.ming.mallchat.common.chat.pojo.Room;
import com.ming.mallchat.common.chat.pojo.RoomFriend;
import com.ming.mallchat.common.common.domain.enums.NormalOrNoEnum;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 86150
 * @date 2023/10/11
 */
public class ChatAdapter {
    public static String generateRoomKey(List<Long> uidList) {
        return uidList.stream()
                .sorted()
                .map(String::valueOf)
                .collect(Collectors.joining());
    }

    public static Room buildRoom(RoomTypeEnum typeEnum) {
        return Room.builder()
                .type(typeEnum.getType())
                .hotFlag(HotFlagEnum.NOT.getType())
                .build();
    }

    public static RoomFriend buildFriendRoom(Long roomId, List<Long> uidList) {
        List<Long> collect = uidList.stream().sorted().collect(Collectors.toList());
        return RoomFriend.builder()
                .roomId(roomId)
                .uid1(collect.get(0))
                .uid2(collect.get(1))
                .roomKey(generateRoomKey(uidList))
                .status(NormalOrNoEnum.NORMAL.getStatus())
                .build();
    }
}
